//
//  AIFCheckApplePayManager.m
//  PywSdk
//
//  Created by Jade on 16/7/27.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "AIFCheckApplePayManager.h"

@implementation AIFCheckApplePayManager

NSString *const CheckApplePay_TID = @"tid";
NSString *const CheckApplePay_GAMEID = @"gameid";
NSString *const CheckApplePay_SIGN = @"sign";
NSString *const CheckApplePay_ORDERNO = @"order_no";
NSString *const CheckApplePay_RECEIPT = @"receipt";
NSString *const CheckApplePay_ACCOUNT = @"account";
NSString *const CheckApplePay_PASSPORTTOKEN = @"passport_token";
NSString *const CheckApplePay_PASSPORT = @"passport";
NSString *const CheckApplePay_TOKEN = @"token";
NSString *const CheckApplePay_ORDER_ACCOUNT = @"order_account";

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.child = self;
        self.paramSource = self;
        self.validate = self;
    }
    return self;
}


#pragma mark - ETAPIManager
- (NSString *)methodName{
    return URL_CHECKAPPLEPAY;
}

- (ETAPIManagerRequestType)requestType{
    return ETAPIManagerRequestTypePost;
}


- (NSString *)seriviceType{
    return [PywAppInfo sharedAppInfo].seriviceType;
}


#pragma mark - ETAPIManagerParamSourceDelegate
- (NSDictionary *)paramsForApi:(ETApiBaseManager *)manager{
    NSString *tid = [PywAppInfo sharedAppInfo].tid;
    NSString *_gameid = [PywAppInfo sharedAppInfo].gameId;
    NSString *apiSecret2 = [AppUtil getApiSecret2:tid apiSecret:[PywAppInfo sharedAppInfo].apisecret];
    NSString *sign = [NSString stringWithFormat:@"%@%@", self.order_no,apiSecret2];
    sign = [PywCipherUtils md5:sign];
    
    MutableDictionary *param = [[MutableDictionary alloc] init];
    [param setObject:self.order_no forKey:CheckApplePay_ORDERNO];
    [param setObject:self.receipt forKey:CheckApplePay_RECEIPT];
    [param setObject:self.order_account forKey:CheckApplePay_ORDER_ACCOUNT];
    [param setObject:[PywPlatformMain sharedPlatformMain].account forKey:CheckApplePay_ACCOUNT];
    if ([PywPlatformMain sharedPlatformMain].accountType ==  UserType_Passport) {
        [param setObject:[PywPlatformMain sharedPlatformMain].passport_Token forKey:CheckApplePay_PASSPORTTOKEN];
        [param setObject:[PywPlatformMain sharedPlatformMain].passport forKey:CheckApplePay_PASSPORT];
    }else {
        [param setObject:[PywPlatformMain sharedPlatformMain].token forKey:CheckApplePay_TOKEN];
        [param setObject:@"" forKey:CheckApplePay_PASSPORT];
    }
    [param setObject:tid forKey:CheckApplePay_TID];
    [param setObject:_gameid forKey:CheckApplePay_GAMEID];
    [param setObject:sign forKey:CheckApplePay_SIGN];
    return param;
}

#pragma mark - ETAPIManagerValidator
- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return YES;
}

- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    return YES;
}
@end
